const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
	plugins: [
		new CleanWebpackPlugin(['dist']),
		new HtmlWebpackPlugin({
			filename: "index.html",
			template: "./src/index.html"
		})
	],
	devServer: {
		contentBase: "./dist"
	},
	entry: {
		index: './src/script/index.js'//chunkname-->index,
	},
	output: {
		path: path.resolve(__dirname, 'dist'),//输出目录,
		filename: 'script/[name].js',//chunkname.js-->index.js
		//如果需要保证css中指定的背景图片正常访问，则需要配置publicPath，最终图片路径则是publicPath加上file-loader指定的name属性
		//publicPath: 'http://127.0.0.1:8848/vue-learning/dist/'
	},
	module: {
	rules: [
		{
		  test: /\.js$/,
		  exclude: /(node_modules|bower_components)/,
		  use: {
			loader: 'babel-loader',
			options: {
				presets: ['@babel/preset-env'],
				plugins: ['@babel/plugin-transform-runtime']
			}
		  }
		}
	  ]
	}
}